#include "SypEngine.h"

#ifdef CHECKMEM
#include "mmgr.h"
#endif
namespace Syp
{

bool Renderable::operator <(const Renderable &r) const
{
	MeshInstance& lhs = (*(this->parent));
	MeshInstance& rhs = (*(r.parent));

	//MI->Material->SubMaterial[ MI->Mesh->drawCall[ indexBlock ]->MaterialID ]->MaterialID]->Texture
	SubMaterial& lm = lhs.getMaterial()->subMaterials[ lhs.getMesh()->getDrawCall( this->indexBlock ).materialID ];
	SubMaterial& rm = rhs.getMaterial()->subMaterials[ rhs.getMesh()->getDrawCall( r.indexBlock ).materialID ];

	/////////////////////////////////////////Pass Types///////////////////////////////////////////
	if( this->pass->getPassType() < r.pass->getPassType() )
	{
		return true;
	}
	else if(this->pass->getPassType() > r.pass->getPassType())
	{
		return false;
	}	
	///////////////////////////////////////Texture///////////////////////////////////
	else if(lm.getTexture() < rm.getTexture())
	{
        return true;
	}
	else if(lm.getTexture() > rm.getTexture())
	{
		return false;
	}
	///////////////////////////////////////Texture End///////////////////////////////////
	///////////////////////////////////////Mesh//////////////////////////////////////////
	else if(lhs.getMesh() < rhs.getMesh())
	{
		return true;
	}
	else if(lhs.getMesh() > rhs.getMesh())
	{
		return false;
	}
	/////////////////////////////////MeshInstance//////////////////////////////////////////
	//I put this above IndexBlock to optimise software skinning, this will allow 1 skinning pass to be applied
	//for all submeshes of a mesh. If sorted by indexBlocks, the same mesh will have to be skinned for every submesh for every meshInstance
	else if(&lhs < &rhs)
	{
		return true;
	}
	else if(&lhs > &rhs)
	{
		return false;
	}
	//////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////IndexBlock/////////////////////////////////////////
	else if(this->indexBlock < r.indexBlock)
	{
		return true;
	}
	else if(this->indexBlock > r.indexBlock)
	{
		return false;
	}	
	else///Else we dont care
	{
		return false;
	}
}

bool Renderable::operator ==(const Renderable &r) const
{
	if(this->parent == r.parent && this->indexBlock == r.indexBlock && this->pass == r.pass)
	{
		return true;
	}
	else
	{
		return false;
	}
}
}
//bool operator ==(const Renderable& l,const Renderable &r)
//{
//	if(l.parent == r.parent && l.indexBlock == r.indexBlock)
//	{
//		return true;
//	}
//	else
//	{
//		return false;
//	}
//}


